package kk.service.impl;

import com.github.pagehelper.PageHelper;
import kk.dao.MemberDao;
import kk.domain.Member;
import kk.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MemberServiceImpl implements MemberService {

    @Autowired
    private MemberDao memberDao;

    @Override
    public List<Member> findAll(Integer pageNum, Integer pageSize) throws Exception {
        PageHelper.startPage(pageNum,pageSize);
        List<Member> memberList = memberDao.findAll();
        return memberList;
    }

    @Override
    public void save(Member member) throws Exception {
        memberDao.save(member);
    }

    @Override
    public Member findById(Integer id) throws Exception {
        Member member = memberDao.findById(id);
        return member;
    }

    @Override
    public void update(Member member) throws Exception {
        memberDao.update(member);
    }

    @Override
    public void deleteById(Integer id) throws Exception {
        memberDao.deleteById(id);
    }

    @Override
    public List<Member> findAllForIntroduce() throws Exception {
        List<Member> memberList = memberDao.findAll();
        return memberList;
    }

    @Override
    public String findLevelById(Integer id) throws Exception {
        String level = memberDao.findLevelById(id);
        return level;
    }

    @Override
    public List<Member> findByName(String name, Integer pageNum, Integer pageSize) throws Exception {
        PageHelper.startPage(pageNum,pageSize);
        List<Member> memberList = memberDao.findByName(name);
        return memberList;
    }
}
